C++ Programming for Linux Systems by Desislav Andreev

C++ Programming for Linux Systems by Desislav Andreev

Author:Desislav Andreev
Language: eng
Format: mobi, epub
Publisher: Packt Publishing Pvt Ltd
Published: 2023-09-20T00:00:00+00:00


Account& operator+=(unsigned amount) noexcept {

Print(" balance before depositing: ", balance,

owner);

auto temp{balance}; // {1}

std::this_thread::sleep_for(1ms);

balance = temp + amount; // {2}

Print(" balance after depositing: ", balance,

owner);

return *this;

}

Account& operator-=(unsigned amount) noexcept {

Print(" balance before withdrawing: ", balance,

owner);

auto temp{balance}; // {1}

balance = temp - amount; // {2}

Print(" balance after withdrawing: ", balance,

owner);

return *this;

}

Looking into the implementation of the operator functions shows that they first read the current balance of the account, then store it in a local object (marker {1}), and finally, using the value of the local object, they increment or decrement with the specified amount.

As simple as it gets!

The resulting value of the new balance of the account is written back into the balance member of the Account structure (marker {2}).

We also need to define a method that will be responsible for the actual money transfer:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.